"""
电影评论人数top10
"""
import pymongo
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType


db = pymongo.MongoClient('localhost', 27017)
douban = db['doubantop250']
item_info = douban['movietop250']

list_result = []

for i in item_info.find():

    list_source = []
    list_source.append(str(i['name']))
    list_source.append(int(i['people_num']))
    list_result.append(list_source)



# 降序排列
list_final = sorted(list_result, key=lambda x: x[1], reverse=True)


bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
bar.add_xaxis([a[0] for a in list_final[:20]])
bar.add_yaxis('电影评论人数', [a[1] for a in list_final[:20]], category_gap="40%")
bar.set_global_opts(
    xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=32, font_size=12)),
    title_opts=opts.TitleOpts(title="豆瓣top250中评论数量top20",
    subtitle="数据来源：https://movie.douban.com/top250?start=0&filter=")
)
bar.set_series_opts(
    label_opts=opts.LabelOpts(is_show=False),
    markpoint_opts=opts.MarkPointOpts(
        data=[
            opts.MarkPointItem(type_="max", name="最大值"),
            opts.MarkPointItem(type_="min", name="最小值")
        ]
    )
)

bar.render('mypeople1.0.html')